package com.example.clw;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;

public class Snow extends Sprite {
	Body mBody;
	
	public Snow(float pX, float pY, float pWidth, float pHeight, TextureRegion pTextureRegion) {
		super(pX, pY, pWidth, pHeight, pTextureRegion);	
		setPhysicsWorld();
	}
	
	public void setPhysicsWorld() {
		FixtureDef fixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);;
		mBody = PhysicsFactory.createCircleBody(CLWService.physicsWorld, this, BodyType.DynamicBody, fixtureDef);
		//mBody.setUserData("snow");
		CLWService.physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, mBody));
	}

	@Override
	public void onManagedUpdate(final float pSecondsElapsed) {
		super.onManagedUpdate(pSecondsElapsed);
		mBody.setTransform(mBody.getPosition().x, mBody.getPosition().y, 0);
	}
	
	/* public void resetPosition() {
		int x = CLWService.generator.nextInt(CLWService.CAMERA_WIDTH - CLWService.SNOW_SIZE);
		int y = 0;
		
		mBody.setTransform(x, y, 0);
	} */
}
